<?php
namespace Home\Controller;

use Think\Controller;
use Admin\Model\Category;
class IndexController extends Controller
{
    public function index()
    {
        $topCate=M('cate')->where("pid=0")->select();
        /*print_r($topCate);*/
        $cate=M('cate')->order("sort")->select();
        $fields=array('id','title','time');
        foreach($topCate as $k=>$v){

            $cids=Category::getChildsId($cate,$v['id']);
            $cids[]=$v['id'];

            $where=array("cid"=>array('in',$cids));
            $topCate[$k]['blog']=M('blog')->where($where)->field($fields)->select();

        }
        /*print_r($topCate);*/
        $this->assign('topCate',$topCate);
        $this->display();
    }

    //顶级菜单的各个题目选项
    public function view(){
        /*dump($_GET);*/
        $id=$_GET['id'];
        $cate=M('cate')->order('sort')->select();
        $cids=Category::getChildsId($cate,$id);
        $cids[]=$id;
        $this->blog=$blog=D('BlogView')->where(array("cid"=>array('in',$cids)))->select();


        /*print_r($blog);*/
        $this->display();
    }

    public function detail(){
        /*echo $_GET['id']."---title";*/
        $cate=M('cate')->order('sort')->select();
        $blogTable=M('blog');
        $this->blog=$blogTable->find($_GET['id']);

        $this->nav=$nav=Category::getParents($cate,$this->blog['cid']);
        /*print_r($nav);*/
        $this->display();
    }
}